package cn.iocoder.yudao.module.system.controller.admin.alluser;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.system.dal.dataobject.alluser.AllUserDO;
import cn.iocoder.yudao.module.system.service.alluser.AllUserService;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;

@Tag(name = "管理后台 - 认证")
@RestController
@RequestMapping("/system/all-user/")
@Validated
@Slf4j
public class AllUserController {
    @Resource
    private AllUserService allUserService;
    @GetMapping("/page")
//    @PreAuthorize("@ss.hasPermission('system:all-user:query')")
    public CommonResult< PageResult<AllUserDO>>  page(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
    @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize, @RequestParam(value = "username",required = false) String username,
    @RequestParam(value = "enterprise",required = false) String enterprise, @RequestParam(value = "type",required = false) Integer type){
        return CommonResult.success(allUserService.findAllUserPage(pageNum, pageSize, enterprise,type,username));
    }

    @GetMapping("/get")
//    @PreAuthorize("@ss.hasPermission('system:all-user:query')")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<AllUserDO>  findAllUserDetail(@RequestParam("id") String id){
        return CommonResult.success(allUserService.findAllUserDetail(id));
    }
    @PostMapping("/create")
//    @PreAuthorize("@ss.hasPermission('system:all-user:create')")
    public CommonResult<Boolean> createAllUser(@RequestBody AllUserDO allUserDO){
        allUserService.createAllUser(allUserDO);
        return CommonResult.success(true);
    }
    @DeleteMapping("/delete")
//    @PreAuthorize("@ss.hasPermission('system:all-user:delete')")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<Boolean> deleteAllUser(@RequestParam("id") String id){
        allUserService.deleteAllUser(id);
        return CommonResult.success(true);
    }
    @PutMapping("/update")
//    @PreAuthorize("@ss.hasPermission('system:all-user:update')")
    public CommonResult<Boolean> updateAllUser(@RequestBody AllUserDO allUserDO){
        allUserService.updateAllUser(allUserDO);
        return CommonResult.success(true);
    }
}
